package com.ych.controller;

import com.ych.beans.Item;
import com.ych.beans.Message;
import com.ych.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/item/item")
public class ItemController {
    @Autowired
    ItemService service;
    @GetMapping
    public Message selectItem(@RequestParam Integer pageNo,@RequestParam(required = false) String key){
        return service.selectItem(pageNo,key);
    }

    @PostMapping
    public Message addItem(@RequestBody Item r){
        return service.addItem(r);
    }

    @DeleteMapping("/{itemid}")
    public Message deleteItem(@PathVariable Integer itemid){
        return service.deleteItem(itemid);
    }

    /**
     * @param r 传入参数时id必须给出
     * @return
     */
    @PutMapping
    public Message updateItem(@RequestBody Item r){
        return service.updateItem(r);
    }
}
